<?php
namespace App\Models;

use Illuminate\Support\Facades\Input;
use Zizaco\Entrust\EntrustRole;

class Role extends EntrustRole{

    protected $fillable = ['name', 'display_name', 'description'];

    public function scopeDisplay_name($query, $display_name = '')
    {
        $display_name = $display_name != '' ? : Input::get('display_name', '');
        if (!empty($display_name)) {
            return $query->where('display_name', 'like', "%{$display_name}%");
        }
        return $query;
    }

    public function scopeName($query, $name = '')
    {
        $name = $name != '' ? : Input::get('name', '');
        if (!empty($name)) {
            return $query->where('name', 'like', "%{$name}%");
        }
        return $query;
    }

    /**
     * belongs to many for user
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function users()
    {
        return $this->belongsToMany('App\User');
    }

    public function permissions()
    {
        return $this->belongsToMany('App\Models\Permission');
    }
}